//
//  Array.swift
//  
//
//  Created by tangbl93 on 2021/2/19.
//

import Foundation

public extension Optional where Wrapped: Collection {

    /// A Boolean value indicating whether the collection is empty or `nil`.
    var yx_isNilOrEmpty: Bool { self?.isEmpty ?? true }
}

public extension Array {
    
    /// Element at the given index if it exists
    subscript(yx index: Index) -> Element? {
        indices ~= index ? self[index] : nil
    }
}

public extension Array {
    
    /// Inserts a new element into the collection at the beginning position.
    mutating func yx_prepend(_ newElement: Element) {
        insert(newElement, at: 0)
    }
}
